import './detail.css';
import {connect} from 'react-redux';
import {Link} from 'react-router';
import Panel from './../../elements/Panel'
import {URL} from '../../libs/Url';
import {Fetch} from '../../libs/';
import CONFIG from '../../libs/config';
import BreadcrumbNavigation from './../../components/BreadcrumbNavigation';

import {
    fetch,
    fetch_remove,
    enable_delete_btn,
    selectAllItem,
    selectItem,
} from '../../actions';
import {SUBJECT, PAGE_SUBJECT} from './../../actions/subject'
const Title = React.createClass({
    render(){
        return (
            <h1 className="text-center mtop35">{this.props.teacher_name}</h1>
        )
    }
});
const Des = React.createClass({
    render(){
        return (
            <p className="text-center auth-row">
                作者： <Link to="#">{this.props.author}</Link> |
                时间：{Moment(this.props.intime).format('YYYY-MM-DD HH:MM:ss')} | 来源：<Link
                to="#">{this.props.source}</Link>
            </p>
        )
    }
});
const Detail = React.createClass({
    getInitialState(){
        return {}
    },
    componentDidMount(){
        const {dispatch} = this.props, self = this;
        Fetch(URL.CLASS_TEACHER_DETAIL, {body: {teacherid: this.props.params.id}})
            .then(res=> {
                self.setState({
                    teacher_name: res.name,
                    teacher_gender: res.gender,
                    teacher_comment: res.comment,
                })
            })
            .catch(e=> {
                console.log(e);
            })

    },
    render(){
        return (
            <div>
                <BreadcrumbNavigation navs={[
                    {url: CONFIG.MENUS_ABSOLUTE.HOME, label: '首页'},
                    {url: CONFIG.MENUS_ABSOLUTE.CLASS_TEACHERS, label: '任课教师'},
                    {label: '教师详情'},
                ]}></BreadcrumbNavigation>

                <Panel>
                    <div className="panel-body">
                        <Title {...this.state}></Title>

                        <div className="blog-img-wide">
                            <img src={require('../../imgs/avatar/avatar'
                                + (/\d+/.test(this.state.teacher_gender)?
                                this.state.teacher_gender+''+((Math.random() * 10).toFixed() % 3):'undefined')
                                + '.png')} alt=""/>
                        </div>
                        <div >
                            { this.state.teacher_comment}
                        </div>

                    </div>
                </Panel>
            </div>
        )
    }
})
function select(state) {
    return {
        [SUBJECT.CLASS_HONOUR_DETAIL]: state.fetchBySubject[SUBJECT.CLASS_HONOUR_DETAIL],
    }
}
export default connect(select)(Detail)